package com.feiyun.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Function Desc: WebMvcConfig
 *
 * @author yan
 * @since 2023/3/26 21:47
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {
//    private final UserLoginInterceptor interceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //是否发送Cookie
                .allowCredentials(true)
                //放行哪些原始域
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*")
                .exposedHeaders("Authorization");
    }

//    /**
//     * 注册自定义拦截器
//     *
//     * @param registry InterceptorRegistry
//     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(interceptor)
//                .addPathPatterns("/user/**")
//                .addPathPatterns("/userInfo/**")
//                .excludePathPatterns("/user/login") //开放登录路径
//                .excludePathPatterns("/user/register")
//                .excludePathPatterns("/user/select");
//    }

}
